{literal}
<script>        
        function createMainUploader(){            
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader-main'),
                fieldname: 'upload[main_photo]',
                multiple: false,
                debug: true,
                needid: false,
                action: '/backend/products/uploadimage',
            });           
        }

        function createUploader(){            
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader'),
                fieldname: 'upload[photo]',
                needid: true,
                action: '/backend/products/uploadimage'
            });           
        }
        
        // in your app create uploader as soon as the DOM is ready
        // don't wait for the window to load  
        createMainUploader();
        createUploader();     
    </script>    
{/literal}
<div class="form">
<FORM method="post" action="/backend/products/save/">
    <H1>{if $Products->isNew()}Добавление продукта{else}Редактирование продукта '{$Products->title}'{/if}</H1>
    <div class="operation">
    	<a href="{$fvConfig->get('dir_web_root')}products/" onclick="go('{$fvConfig->get('dir_web_root')}products/'); return false;" class="left">вернутся к списку</a>
    	<div style="clear: both;"></div>
    </div>
    <div style="width: 50%; float: left;">
    <fieldset>
        <legend>Общая информация</legend>
   		<table>
        	<tr>
        		<td><label for="title">Название:</label></td>
        		<td><input type="text" id="title" name="n[title]" value="{$Products->title|escape|stripslashes}"/></td>
        	</tr>
        	<tr>
        		<td><label for="category_id">Категория:</label></td>
        		<td>{html_options name=n[category_id] id=category_id options=$SectionsOptions selected=$Products->category_id}</td>
        	</tr>
        	<tr>
        		<td><label for="price">Цена:</label></td>
        		<td><input type="text" id="price" name="n[price]" value="{$Products->price|escape}"/></td>
        	</tr>
        	<tr>
        		<td><label for="discount">Скидка:</label></td>
        		<td><input type="text" id="discount" name="n[discount]" value="{$Products->discount|escape}"/></td>
        	</tr>
        	<tr>
        		<td><label for="distributor">Поставщик:</label></td>
        		<td><textarea rows="6" id="distributor" name="n[distributor]">{$Products->distributor|escape|stripslashes}</textarea></td>
        	</tr>
        	<tr>
        		<td><label for="in_stock">Наличие на складе:</label></td>
        		<td>
        			<select name="n[in_stock]" id="in_stock">
        				<option value="yes" {if $Products->in_stock == 'yes'} selected{/if}/>Есть
        				<option value="no" {if $Products->in_stock == 'no'} selected{/if}/>Отсутствует
        				<option value="order" {if $Products->in_stock == 'order'} selected{/if}/>Под заказ
        				<option value="waiting" {if $Products->in_stock == 'waiting'} selected{/if}/>Ожидается
        			</select>
        		</td>
        	</tr>
        	<tr>
        		<td><label for="main_page">Отображать на главной:</label></td>
        		<td><input type="checkbox" name="n[main_page]" value="1" id="main_page" {if $Products->main_page}checked="true"{/if}></td>
        	</tr>
    	</table>
    </fieldset>
    
    <fieldset>
        <legend>Описание</legend>
   		<table>
        	<tr>
        		<td><label for="description">Описание:</label></td>
        		<td width="100%"><textarea rows="6" id="description" name="n[description]">{$Products->description|escape|stripslashes}</textarea></td>
        	</tr>
    	</table>
    </fieldset>
    <div class="buttonpanel">
        <input type="submit" name="save" value="Сохранить" class="button"  onclick="$('redirect').value = '';">
        <input type="submit" name="save_and_return" value="Сохранить и выйти" class="button" onclick="$('redirect').value = '1';">
    </div>
    <input type="hidden" name="id" id="id" value="{$Products->getPk()}" />
    <input type="hidden" id="redirect" name="redirect" value="" />
    </div>
	<div style="float: left; width: 48%; margin-left: 10px;">
		<fieldset>
	        <legend>Фильтры</legend>
	        <div id=filter_div>
	   		{if $Filters}
	   		<table>
	   			<tr>
        			<td><label for="set_filters">Не устанавливать фильтры:</label></td>
        			<td><input type="checkbox" name="set_filters" value="1" {if $set_filters}checked{/if} id="set_filters"></td>
        		</tr>
	        	{foreach from=$Filters item=Filter}
	        	<tr>
	        		<td><label for="description">{$Filter->title}:</label></td>
	        		<td width="100%">
	        			{assign var=fff value=$Filter->getPk()}
	        			{if $Filter->type == 'text'}
	        				<input type="text" id="filter{$Filter->getPk()}" name="filter[{$Filter->getPk()}]" value="{$ProductFilters.$fff}"/>
	        			{elseif $Filter->type == 'drop'}
	        				<select name="filter[{$Filter->getPk()}]" id="filter{$Filter->getPk()}">
	        					{foreach from=$Filter->posible_values key=kk item=val}
	        					<option value="{$kk}" {if $kk == $ProductFilters.$fff}selected{/if} label="{$val}">{$val}</option>
	        					{/foreach}
	        				</select>
	        			{/if}
	        		</td>
	        	</tr>
	        	{/foreach}
	    	</table>
	    	{else}
				<label>Фильтры&nbsp;для&nbsp;категории&nbsp;ещё&nbsp;не&nbsp;установлены</label> 
			{/if}
	    	</div>
	    </fieldset>
		<fieldset>
        	<legend>Загруженная основная фотография</legend>
   			{if !$Products->main_photo.file}
   				<label>Фотография&nbsp;ещё&nbsp;не&nbsp;загружена</label> 
   			{else}
   				<table>
        			<tr>
        				<td></td>
        				<td><label>Имя файла</label></td>
        				<td><label>Описание</label></td>
        			</tr>
   					<tr>
   						<td><a class=link href="{$fvConfig->get('dir_web_root')}products/deleteimage/?id={$Products->getPk()}" onclick="go('{$fvConfig->get('dir_web_root')}products/deleteimage/?id={$Products->getPk()}&photo={$Products->main_photo.file}'); return false;" class="left"><img src="{$fvConfig->get('dir_web_root')}img/delete.png"></a></td>
        				<td><img id="{$Products->main_photo.file}" src="{$Products->getImageDir(true)}{$Products->getImageName($Products->main_photo.file, 'thumb')}"></td>
        				<td>
        					<input type="hidden" id="title" name="n[main_photo][file]" value="{$Products->main_photo.file|escape|stripslashes}"/>
        					<textarea id="title" rows=3 name="n[main_photo][description]">{$Products->main_photo.description|escape|stripslashes}</textarea>
        				</td>
        			</tr>
   				</table>
   			{/if}
    	</fieldset>
		<fieldset>
        	<legend>Основная фотография</legend>
   			<div id="file-uploader-main">		
				<noscript>			
					<p>Please enable JavaScript to use file uploader.</p>
					<!-- or put a simple form for upload here -->
				</noscript>         
			</div>
    	</fieldset>
		
		
		<fieldset>
        	<legend>Загруженные дополнительные фотографии</legend>
   			{if !$Products->photo.0}
   				<label>Фотографии&nbsp;ещё&nbsp;не&nbsp;загружены</label> 
   			{else}
   				<table>
        			<tr>
        				<td></td>
        				<td><label>Имя файла</label></td>
        				<td><label>Описание</label></td>
        			</tr>
   					{foreach item=Photo from=$Products->photo key=key}
   					<tr>
   						<td><a class=link href="{$fvConfig->get('dir_web_root')}products/deleteimage/?id={$Products->getPk()}&photo={$Photo.file}" onclick="go('{$fvConfig->get('dir_web_root')}products/deleteimage/?id={$Products->getPk()}&photo={$Photo.file}'); return false;" class="left"><img src="{$fvConfig->get('dir_web_root')}img/delete.png"></a></td>
        				<td><img id="{$Photo.file}" src="{$Products->getImageDir(true)}{$Products->getImageName($Photo.file, 'thumb')}"></td>
        				<td>
        					<input type="hidden" id="title" name="n[photo][{$key}][file]" value="{$Photo.file|escape|stripslashes}"/>
        					<textarea id="title" rows=3 name="n[photo][{$key}][description]">{$Photo.description|escape|stripslashes}</textarea>
        				</td>
        			</tr>
   					{/foreach}
   				</table>
   			{/if}
    	</fieldset>
    	
    	<fieldset>
        	<legend>Дополнительные фотографии</legend>
   			<div id="file-uploader">		
				<noscript>			
					<p>Please enable JavaScript to use file uploader.</p>
				</noscript>         
			</div>
    	</fieldset>
	</div>
<div style="clear: both;" />
</div>
</form>
</div>
{literal}
<script>
    new MaskedInput('#discount', '9?9', {placeholder:" "});

    function changeInherit(e) {
    	window.blockScreen();
    	new Ajax.Updater('filter_div', {/literal}'{$fvConfig->get('dir_web_root')}ajaxcall/updatefilters'{literal}, {
  		  parameters: { category_id: $("category_id").value },
          onComplete: function (transport) {
       			if ($('contentblocker')) $('contentblocker').hide();         		
           }
  		});
    }
    
    $('category_id').observe('change', changeInherit); 
</script>
{/literal}
